﻿using Newtonsoft.Json;
using Omabar.BLL;
using Omabar.Common;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;

namespace Omabar.CMS.Handler
{
    /// <summary>
    /// FlightAdd 的摘要说明
    /// </summary>
    public class FlightAdd : IHttpHandler, IRequiresSessionState
    {
        public void ProcessRequest(HttpContext context)
        {
            RESP_Info info = new RESP_Info();
            try
            {
                context.Response.ContentType = "text/plain";

                string FLIGHT_CODE = context.Request["FLIGHT_CODE"];
                string FLIGHT_CITY_START = context.Request["FLIGHT_CITY_START"];
                string FLIGHT_CITY_END = context.Request["FLIGHT_CITY_END"];
                string FLIGHT_TIME_START = context.Request["FLIGHT_TIME_START"];
                string FLIGHT_TIME_END = context.Request["FLIGHT_TIME_END"];
                string FLIGHT_PRICE = context.Request["FLIGHT_PRICE"];

                FLIGHT hotel = new FLIGHT()
                {
                    FLIGHT_ID = Util.GetUID(),
                    FLIGHT_CODE = FLIGHT_CODE,
                    FLIGHT_CITY_START = FLIGHT_CITY_START,
                    FLIGHT_CITY_END = FLIGHT_CITY_END,
                    FLIGHT_TIME_START = DateTime.Parse(FLIGHT_TIME_START),
                    FLIGHT_TIME_END = DateTime.Parse(FLIGHT_TIME_END),
                    FLIGHT_PRICE = int.Parse(FLIGHT_PRICE)
                };

                Flight_BLL bll = new Flight_BLL();
                info = bll.Add(hotel);
            }
            catch (Exception ex)
            {
                Tom.Net.Log.LogManager.Error("添加航班失败", ex);
                info.Success = false;
                info.Title = "错误";
                info.Tip = "<h5><p>添加航班失败</p></h5>";
                info.Url = "FlightAdd.aspx";
            }

            context.Response.Write(JsonConvert.SerializeObject(info));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}